1. Field of the Invention
This invention relates to a debugging method and a debugging apparatus for a microcomputer system and a recording medium on which a debug program is recorded. More specifically, the present invention relates to a debugging method and a debugging apparatus wherein a debugged state of a system at a certain point of time during operation of the system is stored and thereafter restored to perform re-execution from the point of time and a recording medium on which a debug program for the debugging method and the debugging apparatus is recorded.
2. Description of the Related Art
When it is tried to develop a system newly, it must be verified in a debugging step or an inspection step whether or not a program for use with the system operates correctly as intended by a designer. In those steps, the program is inputted to a debugging apparatus so that simulation of operation or debugging is performed by the debugging apparatus. In this instance, unless specified specifically, the debugging apparatus starts its simulation beginning at the top of the program.
However, in the debugging step or inspection step for a program, debugging or inspection is in most cases performed based on an operation test procedure prepared by a designer of the program for confirming whether or not the system operates in accordance with the specifications. Then, if correct operation continues up to a portion of the program and thereafter false operation is performed, then the location is detected, and the program is corrected based on a result of the detection. Then, the debugging or inspection is repeated after it is confirmed that the corrected portion of the program is now operating correctly.
In short, in the process above, there is correct operation up to a specific point of time in the program, and when a state of incorrect operation is detected at a next point of time the program is repaired, correct operation is reconfirmed and the operation is repeated to check if there is a subsequent place of incorrect operation.
Thus, in order to perform a debugging operation efficiently, a function to restore a debugged state at a certain point of time and perform re-execution of a program beginning at a place in the program other than the top is required.
In conventional debugging methods and debugging apparatus, as a function to restore a debugged state at a certain point of time to allow re-execution from that point of time, two functions of a back execution function and a function to hold state are available. The back execution function is a function to store, when an instruction is executed, information of a memory, a register and so forth whose states have changed as a result of the execution of the instruction into a buffer for exclusive use and to return, upon back execution, the debugged state in accordance with the stored contents of the buffer by one-by-one instruction to the condition prior to the execution condition. The function to hold a state is a function to store a debugged state at certain point of time into a state storage file and, when it is desired to restore the debugged state at that point of time, the debugged state is restored by reading in the state storage file.
A conventional debugging apparatus is described in detail with reference to the drawings. FIG. 1 is a diagrammatic view showing a system construction of a conventional debugging apparatus.
Recording medium 501 has a debug simulation program recorded thereon. Contents of the program are written into debugging apparatus 503 and used to control operation of simulation unit 505, debugger unit 506, state storage/restoration unit 507 and so forth which are components of debugging apparatus 503. Debugging apparatus 503 performs simulation or debugging processing in response to an inputted command from information IN/OUT apparatus 502. Upon starting of debugging, a down load command is inputted from information IN/OUT apparatus 502 to down load object code file 504 of a program, which is an object of debugging, to debugging apparatus 503.
Simulation unit 505 in debugging apparatus 503 executes the down loaded program by one-by-one instruction by ordinary execution unit 508. If a command to acquire information for back execution has been issued prior to the execution, then each time an instruction is executed, the value of a register, a memory or the like which has been changed by the instruction is stored into a buffer for an exclusive use of back execution unit 509. When a back execution command is issued, back execution unit 509 restores the state prior to execution of an instruction by one-by-one instruction using the information stored in the buffer.
Debugger unit 506 in debugging apparatus 503 performs processing regarding a debugging function for breaking, tracing and so forth. A break point at which execution of a program is interrupted when a certain event occurs or a trace are recorded, and an instruction execution situation, a memory access situation or the like at a point of time when a certain event occurs, is set by an individual command. Events and actions, such as breaking, tracing and so forth when such events occur, which are set by such commands, are registered in event processing unit 510 and action processing unit 511 in debugger unit 506, respectively, and are processed in the following manner when the instructions are executed.
In event processing unit 510, each time one instruction is executed, it is checked by event detection unit 512 whether or not a state which corresponds to any of the event conditions set in advance has occurred, and if an event is detected, then this is reported to action processing unit 511 through event occurrence reporting unit 513. Action processing unit 511 checks whether or not an action which originates from the event reported thereto is included in the actions registered in advance therein, and if the action is a registered one, then processing of the action is performed by a suitable one of break processing unit 514, trace processing unit 515 and so forth.
In state storage/restoration unit 507 in debugging apparatus 503, state storage unit 516 stores a debugged state into state storage file 518 when a debugged state storage command is issued or at a predetermined timing determined for the debugging apparatus. Predetermined timing here signifies a timing after several instructions are executed or several commands are issued or when simulation/debugging comes to an end. State restoration unit 517 performs, when a state restoration command is issued, based on an arbitrary one of state storage files 518, processing to return the debugged state to the state when the file was stored.
A conventional debugging method is described in detail with reference to the drawings. FIGS. 2A and 2B are flow charts illustrating a processing flow of a conventional debugging method.
The debugging apparatus when started enters a command input waiting mode (601) so that it receives an inputted command from a user and performs an operation conforming to the command to realize simulation or debugging. If a command is inputted (602), then the debugging apparatus analyzes the command. In this instance, if a debugged state changes as a result of processing of the command, then a command counter is incremented (603). If a result of the command analysis reveals that the command is an execution command (604), then an execution flag is set to ON (605) and one instruction is executed (606).
Then, debugging processing which is to be processed incidentally to the execution of one instruction is performed. First, if a back execution information acquisition flag is ON (607), then information of a memory, a register or the like which has changed as a result of the execution of the instruction is stored into a back execution information storage buffer (608). The ON/OFF operation of the back execution information acquisition flag is performed with a back execution information acquisition selection command as hereinafter described. Then, a counter for counting the number of instructions executed is incremented (609), and if the counter value becomes equal to an instruction number determined by the system of the debugging apparatus (610), then the current debugged state is stored into a state storage file (611) and the instruction number counter is reset to 0 (612). Further, it is checked whether or not, as a result of the execution of the command, a state which corresponds to any of events registered by the user is satisfied (613), and if such an event is detected (614), then processing of an action registered in correlation with the event is performed (615).
This action may be acquisition of trace information, a request for a break or the like. If the action is a request for a break (616), then the execution flag is changed to OFF (618), thereby ending the processing. When no event is detected or after action processing other than breaking correlated to an event is completed, it is confirmed whether or not an execution ending situation has occurred (617), and if an execution ending situation has occurred, then the execution flag is changed to OFF (618). In any other case, a next instruction is executed (606). A situation in which it is necessary to end the execution may be a case wherein a compulsory ending requesting command is issued or an execution ending address designated by an execution command is reached. Further, such registration of an event or an action as described above is performed using an event setting command or an action setting command as hereinafter described.
If a back execution information acquisition selection command is inputted to the debugging apparatus (619), then the back execution information acquisition flag is set to ON when it is selected to acquire back execution information, but to OFF when it is selected not to acquire back execution information (620). When a back execution command is inputted (621), the back execution flag is changed to ON (622), and if back execution information is available (623), then back execution is performed one by one instruction based on the back execution information (624). If no back execution information is available, then the back execution flag is changed to OFF (626). Also when a back execution ending point designated by the user is reached (625), the back execution flag is changed to OFF (626).
If an event setting command or an action setting command for breaking, tracing of the like is inputted (627), then the set event or action information is registered into the event processing unit or the action processing unit (628). If a state storage command is inputted (629), then the current debugged information is stored into a file (630). If a state restoration command is inputted (631), an arbitrary state storage file is selected and contents of the file are read in to restore the debugged state (632). Also for the other commands, processing of the commands is performed (636).
After processing of the commands is completed, if the count value of the command counter measured in step 603 reaches the instruction number determined by the system of the debugging apparatus (637), then the current debugged state is stored into the state storage file (638) and the count value of the command counter is reset to 0 to return to a command input waiting state (601). When a debug ending command is inputted (633), it can be selected whether or not the current debugged state should be stored (634), and when necessary, storage of the current debugged state into a state storage file is performed (635), thereby ending the processing of the debugging apparatus.
As described above, with the conventional debugging apparatus and debugging method, two functions of the back execution function and the function to hold state are available as functions to restore a debugged state at a certain point of time and allow re-execution of processing from the point of time. However, with the back execution function, each time an instruction is executed, information of memory or a register which exhibits a variation as a result of execution of the instruction must be stored into a buffer for exclusive use, and therefore, from the relationship of the capacity, restoration is possible only for a limited number of instructions. Also the instruction execution performance is deteriorated by the storage processing of such variation information. Further, the conventional function to hold state can store a debugged state only at limited timings such as when a state storage command is issued, after several instructions are executed, after several commands are issued, or when debugging is completed. This, however, may result in production of a large number of files which store debugged states at locations at which no debugged state need be stored actually.
Further, much time is required also to retrieve a file with which an intended debugged state can be restored from among a large number of files. For example, in order to restore state at point of time prior to execution of a certain address of a certain function, such a sequence of operations are required that a file with which a debugged state at a preceding address nearest to the certain address can be restored is selected to restore the debugged state and then re-execution from the point of time up to a desired address is performed. If a debugged state to be re-executed is a condition at a point of time at which a certain value is written into a certain memory, then a state storage file which has stored a state prior to occurrence of the state at the point nearest to the point of time at which the value was written into the memory must be retrieved. However, with the prior art, it is difficult to retrieve the state storage file.